<template>
  <a-layout class="model-selection-layout">
    <a-layout-header class="header">
      <div class="logo">
        <img src="../assets/logo.svg" alt="牙之初" />
        <span>口腔诊疗平台</span>
      </div>
      <div class="header-menu">
        <a-menu
          mode="horizontal"
          :selectedKeys="['1']"
          theme="light"
        >
          <a-menu-item key="1">工作台</a-menu-item>
          <a-menu-item key="2">病例</a-menu-item>
          <a-menu-item key="3">模型预览</a-menu-item>
        </a-menu>
      </div>
      <div class="header-right">
        <a-dropdown>
          <a class="user-dropdown" @click.prevent>
            <a-avatar style="background-color: #1890ff">
              <template #icon><UserOutlined /></template>
            </a-avatar>
            <span class="username">医生</span>
          </a>
          <template #overlay>
            <a-menu>
              <a-menu-item key="1">个人设置</a-menu-item>
              <a-menu-item key="2">退出登录</a-menu-item>
            </a-menu>
          </template>
        </a-dropdown>
      </div>
    </a-layout-header>

    <a-layout-content class="content">
      <div class="page-header">
        <div class="page-title">
          <router-link to="/dashboard">
            <a-button type="link" class="back-button">
              <template #icon><ArrowLeftOutlined /></template>
              返回工作台
            </a-button>
          </router-link>
          <h1>选择模型</h1>
        </div>
      </div>

      <div class="model-selection-container">
        <div class="model-cards">
          <div 
            v-for="(model, index) in models" 
            :key="index"
            class="model-card"
            :class="{ selected: selectedModel === index }"
            @click="selectModel(index)"
          >
            <div class="model-card-inner">
              <div class="model-title">{{ model.title }}</div>
              <div class="model-duration">服务周期: <span class="duration-value">{{ model.duration }}</span></div>
              <div class="model-features">
                <div v-for="(feature, idx) in model.features" :key="idx" class="model-feature">
                  <CheckCircleFilled style="color: #52c41a; margin-right: 8px;" />
                  <span>{{ feature }}</span>
                </div>
              </div>
              <a-button 
                type="primary" 
                class="select-button"
                :class="{ selected: selectedModel === index }"
                @click.stop="confirmSelection(index)"
              >
                选择
              </a-button>
            </div>
          </div>
        </div>
      </div>

      <div class="navigation-buttons">
        <a-button @click="goBack">上一步</a-button>
        <a-button type="primary" @click="goNext" :disabled="selectedModel === null">下一步</a-button>
      </div>
    </a-layout-content>
  </a-layout>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { 
  UserOutlined,
  ArrowLeftOutlined,
  CheckCircleFilled
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'

const router = useRouter()
const selectedModel = ref(null)

// 模型数据
const models = [
  {
    title: '牙之初-乳牙版',
    duration: '1年',
    features: [
      '适用于儿童乳牙期（3-6岁）的牙齿排列矫正，帮助纠正各种乳牙排列不齐的问题。',
      '全套包括传统的治疗，硅胶矫治器，固持矫治器。',
      '服务周期1年。'
    ]
  },
  {
    title: '牙之初-恒牙版',
    duration: '2年',
    features: [
      '适用于儿童恒牙期（6-12岁）的牙齿排列矫正，帮助纠正各种恒牙排列不齐的问题。',
      '全套包括传统的治疗，硅胶矫治器，固持矫治器。',
      '服务周期2年。',
      '不限回访次数。'
    ]
  },
  {
    title: '牙之初Plus',
    duration: '3年',
    features: [
      '适用于儿童乳牙和恒牙期（3-12岁）与头颅面畸形，帮助纠正各种乳牙和恒牙排列不齐的问题。',
      '全套包括传统的治疗，硅胶矫治器，固持矫治器。',
      '服务周期3年。',
      '不限回访次数。'
    ]
  },
  {
    title: '牙之初Pro',
    duration: '5年',
    features: [
      '适用于儿童恒牙期（6-16岁）与头颅面畸形，帮助纠正各种恒牙排列不齐的问题。',
      '全套包括传统的治疗，硅胶矫治器，固持矫治器。',
      '服务周期5年。',
      '不限回访次数。'
    ]
  }
]

// 选择模型
const selectModel = (index) => {
  selectedModel.value = index
}

// 确认选择
const confirmSelection = (index) => {
  selectedModel.value = index
  message.success(`已选择 ${models[index].title}`)
}

// 返回上一步
const goBack = () => {
  router.push('/new-case')
}

// 进入下一步
const goNext = () => {
  if (selectedModel.value !== null) {
    // 这里可以保存选择的模型数据，然后跳转到病例详情页
    message.success('模型选择成功，创建病例完成')
    router.push('/dashboard')
  } else {
    message.warning('请先选择一个模型')
  }
}
</script>

<style scoped>
.model-selection-layout {
  min-height: 100vh;
}

.header {
  background: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  height: 64px;
  position: fixed;
  width: 100%;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  margin-right: 48px;
}

.logo img {
  height: 32px;
  margin-right: 8px;
}

.logo span {
  font-size: 18px;
  font-weight: 600;
  color: #1890ff;
}

.header-menu {
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
}

.user-dropdown {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.username {
  margin-left: 8px;
  color: rgba(0, 0, 0, 0.65);
}

.content {
  margin-top: 64px;
  padding: 24px;
  background: #f0f2f5;
  min-height: calc(100vh - 64px);
}

.page-header {
  margin-bottom: 24px;
}

.page-title {
  display: flex;
  align-items: center;
}

.page-title h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.back-button {
  padding: 0;
  margin-right: 16px;
}

.model-selection-container {
  margin-bottom: 24px;
}

.model-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
}

.model-card {
  width: 280px;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s;
  cursor: pointer;
  position: relative;
}

.model-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.model-card.selected {
  border: 2px solid #1890ff;
  box-shadow: 0 5px 15px rgba(24, 144, 255, 0.2);
}

.model-card-inner {
  background: linear-gradient(to bottom, #ffeb3b, #ffc107);
  padding: 24px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.model-card:nth-child(1) .model-card-inner {
  background: linear-gradient(to bottom, #ffcc80, #ffb74d);
}

.model-card:nth-child(2) .model-card-inner {
  background: linear-gradient(to bottom, #fff176, #ffee58);
}

.model-card:nth-child(3) .model-card-inner {
  background: linear-gradient(to bottom, #fff176, #ffee58);
}

.model-card:nth-child(4) .model-card-inner {
  background: linear-gradient(to bottom, #81d4fa, #4fc3f7);
}

.model-title {
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  margin-bottom: 16px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.model-duration {
  font-size: 16px;
  text-align: center;
  margin-bottom: 16px;
  color: rgba(0, 0, 0, 0.85);
}

.duration-value {
  font-size: 20px;
  font-weight: 600;
  color: #1890ff;
}

.model-features {
  flex: 1;
  margin-bottom: 16px;
}

.model-feature {
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}

.select-button {
  width: 100%;
}

.select-button.selected {
  background-color: #52c41a;
  border-color: #52c41a;
}

.navigation-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  padding: 24px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
</style>
